{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on built-in function hash in module builtins:\n\nhash(obj, /)\n    Return the hash value for the given object.\n    \n    Two objects that compare equal must also have the same hash value, but the\n    reverse is not necessarily true.\n\n"
    }
   ],
   "source": [
    "help(hash)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on built-in function id in module builtins:\n\nid(obj, /)\n    Return the identity of an object.\n    \n    This is guaranteed to be unique among simultaneously existing objects.\n    (CPython uses the object's memory address.)\n\n"
    }
   ],
   "source": [
    "help(id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "140708994654608"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "a = 1\n",
    "id(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "140708994654640"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "a = 2\n",
    "id(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "140708994654672"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "a = a + 1\n",
    "id(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "'abcdefghijklmnopqrstuvwxyz'"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "src = ''\n",
    "for i in range(26):\n",
    "    src = src + chr(i + 97)\n",
    "src"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on method_descriptor:\n\nindex(...)\n    S.index(sub[, start[, end]]) -> int\n    \n    Return the lowest index in S where substring sub is found, \n    such that sub is contained within S[start:end].  Optional\n    arguments start and end are interpreted as in slice notation.\n    \n    Raises ValueError when the substring is not found.\n\n"
    }
   ],
   "source": [
    "help(str.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "'defghijklmnopqrstuvwxyzabc'"
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "tar = src[3:] + src[:3]\n",
    "tar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "khoor zruog!\n"
    }
   ],
   "source": [
    "init_str = 'hello world!'\n",
    "\n",
    "res = ''\n",
    "for ch in init_str:\n",
    "    if ch in src:\n",
    "        index = src.index(ch)\n",
    "        res = res + tar[index]\n",
    "    else:\n",
    "        res = res + ch\n",
    "        \n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "hello world!\n"
    }
   ],
   "source": [
    "init_str = 'khoor zruog!'\n",
    "\n",
    "res = ''\n",
    "for ch in init_str:\n",
    "    if ch in src:\n",
    "        index = tar.index(ch)\n",
    "        res = res + src[index] \n",
    "    else:\n",
    "        res = res + ch\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "I oryh x!\n"
    }
   ],
   "source": [
    "def encryptIt(init_str: str) -> str:\n",
    "    '''used for encrypt a string\n",
    "    attribute:\n",
    "        init_str: str\n",
    "        res: result of encrypt\n",
    "    '''\n",
    "    global src, tar\n",
    "    res = ''\n",
    "    for ch in init_str:\n",
    "        if ch in src:\n",
    "            index = src.index(ch)\n",
    "            res = res + tar[index]\n",
    "        else:\n",
    "            res = res + ch\n",
    "    return res\n",
    "\n",
    "print(encryptIt('I love u!')) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "I love u!\n"
    }
   ],
   "source": [
    "def decryptIt(init_str: str) -> str:\n",
    "    '''used for decrypt a string\n",
    "    attribute:\n",
    "        init_str: str\n",
    "        res: result of decrying\n",
    "    '''\n",
    "    global src, tar\n",
    "    res = ''\n",
    "    for ch in init_str:\n",
    "        if ch in tar:\n",
    "            index = tar.index(ch)\n",
    "            res = res + src[index]\n",
    "        else:\n",
    "            res = res + ch\n",
    "    return res\n",
    "\n",
    "print(decryptIt('I oryh x!')) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "assert('abcdefghijklmnopqrstuvwxyz!' == decryptIt(encryptIt('abcdefghijklmnopqrstuvwxyz!')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on function encryptIt in module __main__:\n\nencryptIt(init_str: str) -> str\n    used for encrypt a string\n    attribute:\n        init_str: str\n        res: result of encrypt\n\n"
    }
   ],
   "source": [
    "help(encryptIt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "Help on function decryptIt in module __main__:\n\ndecryptIt(init_str: str) -> str\n    used for decrypt a string\n    attribute:\n        init_str: str\n        res: result of decrying\n\n"
    }
   ],
   "source": [
    "help(decryptIt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "I oryh brx!\nI love you!\n"
    }
   ],
   "source": [
    "src = 'abcdefghijklmnopqrstuvwxyz'\n",
    "def ceyptIt(init_str: str, if_decrypt: bool = False) -> str:\n",
    "    '''used for encrypt or decrypt a string\n",
    "    attribute:\n",
    "        init_str: str\n",
    "        res: result of processing\n",
    "\n",
    "    '''\n",
    "    global src \n",
    "    res = ''\n",
    "    for ch in init_str:\n",
    "        if ch in src:\n",
    "            oidx = src.index(ch)\n",
    "            nidx = (oidx - 3) % 26 \\\n",
    "                if if_decrypt \\\n",
    "                else (oidx + 3) % 26\n",
    "            res = res + src[nidx]\n",
    "        else:\n",
    "            res = res + ch\n",
    "    return res\n",
    "\n",
    "print(ceyptIt('I love you!'))\n",
    "print(ceyptIt('I oryh brx!', True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "2\n1\n"
    }
   ],
   "source": [
    "\n",
    "a = 1\n",
    "\n",
    "def mytest():\n",
    "    a = 2\n",
    "    print(a)\n",
    "\n",
    "mytest()\n",
    "print(a)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}